package com.example.fairplay.newfpregistration.fragments;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.fairplay.newfpregistration.R;
import com.example.mylibrary.activity.BaseFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by fairplay on 2018/5/31.
 * 关于fragment
 */

public class AboutFragment extends BaseFragment {

    @Bind(R.id.tv_telephone)
    TextView tvTelephone;
    @Bind(R.id.rl_telephone)
    RelativeLayout rlTelephone;
    @Bind(R.id.tv_soft_version)
    TextView tvSoftVersion;
    @Bind(R.id.rl_soft_version)
    RelativeLayout rlSoftVersion;
    @Bind(R.id.tv_website)
    TextView tvWebsite;
    @Bind(R.id.rl_website)
    RelativeLayout rlWebsite;
    @Bind(R.id.tv_wechat)
    TextView tvWechat;
    @Bind(R.id.rl_wechat)
    RelativeLayout rlWechat;
    @Bind(R.id.tv_infomation)
    TextView tvInfomation;
    @Bind(R.id.rl_infomation)
    RelativeLayout rlInfomation;
    private View mView;
    private int version;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_about, container, false);
        ButterKnife.bind(this, mView);
        initObjects();
        initViews();
        initData();
        setListeners();

        return mView;
    }


    @Override
    protected void findViews() {

    }

    @Override
    protected void initObjects() {

    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {
        String version=String.valueOf(getVersion());
        tvSoftVersion.setText(version);
        tvInfomation.setText(getIMEI());
    }

    @Override
    protected void setListeners() {

    }

    /**
     * 获取IMEI
     *
     * @return
     */
    private String getIMEI() {
        TelephonyManager telephonyManager = (TelephonyManager) mActivity.getSystemService(Context.TELEPHONY_SERVICE);
        String imei = telephonyManager.getDeviceId();
        return imei;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    /**
     * 获取软件版本号
     */
    private int getVersion(){
        try {
            PackageInfo packageInfo=mActivity.getApplication().getPackageManager().getPackageInfo(mActivity.getPackageName(),0);
            version=packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        return version;
    }
}
